package cn.pixelsol.google.translate;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class Browser {
	private String hostname;
	private Integer port;
	private String url;

	public String getUrl() {
		return this.url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setProxy(String ip, Integer port) {
		this.hostname = ip;
		this.port = port;
	}

	public String executeGet() throws IOException {
		String result = null;
		
		Map<String, String> headerMap = new HashMap<String, String>();
		headerMap.put("accept", "*/*");
		headerMap.put("connection", "Keep-Alive");
		headerMap.put("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
		
		if (this.hostname != null && !"".equals(this.hostname)) {
			result = String.valueOf(HttpUtil.doGet(this.url, headerMap, this.hostname, this.port));
		} else {
			byte[] bArr = HttpUtil.doGet(this.url, headerMap);
			if(bArr!=null) {
				result = new String(bArr);
			}
		}

		return result;
	}
}
